package cn.sunzn.reflectcase;

import com.quanyan.util.TypeUtil;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;

public class InvokeMethod {
	public static void main(String[] args) {
		try {
			String classPath="cn.sunzn.reflectcase.TestMethod";
			Class<?> clazz = Class.forName(classPath);
			Constructor<?> constructor = clazz.getDeclaredConstructor();
	        Object obj=constructor.newInstance();
	        
	        Class<?> [] parameterTypes=null;
	       
	        int flag=1;
	        Method[] mothodNames=clazz.getMethods();
	        for(int i=0;i<mothodNames.length;i++){
	        	if("getResult2".equals(mothodNames[i].getName())){
	        		if(flag==1){
	        			parameterTypes =mothodNames[i].getParameterTypes();
	        			break;
	        		}else{
	        			flag++;
	        		}
	        	}
	        }
	        
	        Method  handleMethod=clazz.getDeclaredMethod("getResult2", parameterTypes);
	        String [] dataStr=new String[]{"6","8","好不好","ok好不好"};
	        dataStr=null;
	        Object[] data=TypeUtil.typeTransform(parameterTypes, dataStr,null,null);
	        
	        Object result=handleMethod.invoke(obj, data);
	        System.out.println("result:"+result);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
    }
	   
    
	
}
